package com.abbas.CayTcore.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentStatePagerAdapter
import com.abbas.CayTcore.base.BaseFragment
import com.abbas.CayTcore.databinding.FragmentWindingBinding
import com.abbas.CayTcore.entity.CoreLW
import com.abbas.CayTcore.presenter.WindingPresenter
import com.abbas.CayTcore.view.ViewContract
import q.rorbin.verticaltablayout.adapter.TabAdapter

//   -_-||  气死我了
class WindingFragment(private val core: CoreLW) :
    BaseFragment<ViewContract.WindingView, WindingPresenter, FragmentWindingBinding>(),
    ViewContract.WindingView {

    override fun initPresenter(): WindingPresenter {
        return WindingPresenter()
    }

    override fun showLoading() {
        binding.refresh.isRefreshing = true
    }

    override fun closeLoading() {
        binding.refresh.isRefreshing = false
    }

    override fun getAllCore() {
        presenter.getCore(core)

    }

    override fun onCoreDataGet(vpAdapter: FragmentStatePagerAdapter, tabAdapter: TabAdapter) {
        binding.vp.adapter = vpAdapter
        binding.verticalTabLayout.apply {
            setupWithViewPager(binding.vp)
            setTabAdapter(tabAdapter)
        }
    }

    override fun initData() {
        getAllCore()
    }

    override fun initEvent() {
        binding.refresh.setOnRefreshListener {
            getAllCore()
        }
    }

    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): FragmentWindingBinding {
       return FragmentWindingBinding.inflate(inflater, container, false)
    }
}